<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>注册</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/signin.css">
    <script src="${pageContext.request.contextPath}/static/js/jquery-3.6.0.js"></script>
</head>

<body class="text-center">
<form class="form-signin">
    <img class="mb-4" alt="" src="${pageContext.request.contextPath}/static/img/register.svg" width="72" height="72">
    <input type="text" name="name" id="name" class="form-control" placeholder="姓名" required autofocus="">
    <input type="password" name="password" id="password" class="form-control" placeholder="密码" required>
    <input type="password" name="passwordTwo" id="passwordTwo" class="form-control" placeholder="确认密码" required="">
    <input type="text" name="eid" id="eid" class="form-control" placeholder="工号" required>
    <div class="form-group" style="margin-top: 10px">
        <select class="form-control"  name="role" id="role" style="height: 45px">
            <option value="管理员">管理员</option>
            <option value="员工">员工</option>
        </select>
    </div>
    <button class="btn btn-lg btn-primary btn-block" type="button" id="submitRegister">注册</button>
    <a class="btn btn-lg btn-info btn-block" href="${pageContext.request.contextPath}/toLogin">登录</a>
    <p class="mt-5 mb-3 text-muted">2022.12.18</p>
</form>
</body>
<script type="module">
    $('#submitRegister').on('click',function (){
        let name = $('#name').val();
        let password = $('#password').val();
        let passwordTwo = $('#passwordTwo').val();
        let eid = $('#eid').val();
        let role = $('#role').val()
        console.log(role);
        $.ajax({
            url:'http://localhost:8080/register/',
            type:'post',
            data:{
                name:name,
                password:password,
                eid:eid,
                role:role,
                passwordTwo:passwordTwo,
            },
            success(resp){
                if(resp === 'true'){
                    location.href = "/toLogin";
                }else{
                    alert("注册失败！");
                }
            }
        })
    })
</script>
</html>